package com.xianda.spring.service;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@Service
public class FileService {

	private static XSSFWorkbook workbook2007;

	public static void main(String[] args) throws IOException {
		File excelFile = new File("E:\\work\\poi.xlsx");
		FileInputStream is = new FileInputStream(excelFile);// 获取文件输入流
		workbook2007 = new XSSFWorkbook(is);
		XSSFSheet sheet = workbook2007.getSheetAt(0);// 取出第一个工作表，索引是0
		int c = sheet.getLastRowNum();
		System.out.println("rows=" + c);
		// 开始循环遍历行，表头不处理，从1开始
		XSSFCell cell;
		for (int i = 0; i <= c; i++) {
			XSSFRow row = sheet.getRow(i);// 获取行对象
			if (row == null) {// 如果为空，不处理
				continue;
			}
			for (int j = 0; j < row.getLastCellNum(); j++) {
				cell = row.getCell(j);
				System.out.println(cell.toString());
			}

		}

	}

	private static String getStringCellValue(XSSFCell cell) {
		String strCell = "";
		strCell = cell.toString();
		return strCell;
	}

}
